<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var text = 'I# #a#m# #a# #girl#,# #I# #like# #d#a#n#c#i#n#g#!';
        var lenght = text.length;
        function Strtemp(soure, start) {
            return soure.slice(0, start);
        }
        var sum = 0;
        for (var i = 1; i <= lenght; i++) {
            if (Strtemp(text, i) == '#') {
                sum++;
            }
        }
        alert(text + "共有" + sum + "个#");
    </script>
</head>

<body>

</body>

</html>